package com.neusoft.dibuy.myarray;

import java.util.Arrays;

public class QuickSort {
    public static void main(String[] args)
    {
        int[] arr = { 7,9,6,2,5,1,0,3,8,4  };
        quickSort(arr, 0 , arr.length - 1);
        System.out.println(Arrays.toString(arr));
    }
    private static void quickSort(int[] is, int left, int right) {
        int  l =left;
        int r =  right;
        if (left >=right){
            return;
        }
        int mid =  left;
        while (left < right  ){
            int base =  is[left];
            mid =  left;
//            找到第一个比base 小的数的位置
            while ( right > -1 &&  base <  is[right] ){
                right--;
            }
            int temp = is[left];
            is[left] = is[right];
            is[right] = temp;
            mid = right;
            while ( left < is.length && base > is[left] ){
                left++;
            }
            temp = is[left];
            is[left] = is[right];
            is[right] = temp;
            mid = left;
        }
        quickSort(is, l, mid-1);
        quickSort(is, mid + 1, r);
    }
}
